From 314137c8c97237753675e8195980c8c56f434499 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonas=20Dre=C3=9Fler?= Date: Sun, 13 Jul 2025 12:01:10 +0200 Subject: [PATCH] switcherPopup: Move to a ClutterGesture for closing the popup When the user presses a mouse button outside of the switcherPopup, the popup should close. This broke when we moved StButton to ClutterGesture, because the button_press_event() handler in switcherPopup will close the popup before the click gesture recognizes. Since we're trying to move away from direct event handling anyway, port this functionality to a LongPressGesture with a duration of 0, so that the popup closes immediately on button press as it used to. Part-of: --- js/ui/switcherPopup.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/js/ui/switcherPopup.js b/js/ui/switcherPopup.js index 3af9188a5..790ac091e 100644 --- a/js/ui/switcherPopup.js +++ b/js/ui/switcherPopup.js @@ -68,6 +68,22 @@ export const SwitcherPopup = GObject.registerClass({ coordinate: Clutter.BindCoordinate.ALL, })); + const longPressGesture = new Clutter.LongPressGesture({ + long_press_duration_ms: 0, + }); + longPressGesture.connect('may-recognize', () => { + const coords = longPressGesture.get_coords_abs(); + const actorAtCoords = + global.stage.get_actor_at_pos(Clutter.PickMode.REACTIVE, coords.x, coords.y); + + return !this._switcherList?.contains(actorAtCoords); + }); + longPressGesture.connect('recognize', () => { + // User clicked outside + this.fadeAndDestroy(); + }); + this.add_action(longPressGesture); + // Initially disable hover so we ignore the enter-event if // the switcher appears underneath the current pointer location this._disableHover(); @@ -223,12 +239,6 @@ export const SwitcherPopup = GObject.registerClass({ return Clutter.EVENT_STOP; } - vfunc_button_press_event() { - /* We clicked outside */ - this.fadeAndDestroy(); - return Clutter.EVENT_PROPAGATE; - } - _scrollHandler(direction) { if (direction === Clutter.ScrollDirection.UP) this._select(this._previous()); -- 2.39.5